home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / command / install.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  17.7 KB  |  501 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """distutils.command.install
  5.  
  6. Implements the Distutils 'install' command."""
  7. from distutils import log
  8. __revision__ = '$Id: install.py 62788 2008-05-06 22:41:46Z christian.heimes $'
  9. import sys
  10. import os
  11. import string
  12. from types import *
  13. from distutils.core import Command
  14. from distutils.debug import DEBUG
  15. from distutils.sysconfig import get_config_vars
  16. from distutils.errors import DistutilsPlatformError
  17. from distutils.file_util import write_file
  18. from distutils.util import convert_path, subst_vars, change_root
  19. from distutils.util import get_platform
  20. from distutils.errors import DistutilsOptionError
  21. from site import USER_BASE
  22. from site import USER_SITE
  23. if sys.version < '2.2':
  24.     WINDOWS_SCHEME = {
  25.         'purelib': '$base',
  26.         'platlib': '$base',
  27.         'headers': '$base/Include/$dist_name',
  28.         'scripts': '$base/Scripts',
  29.         'data': '$base' }
  30. else:
  31.     WINDOWS_SCHEME = {
  32.         'purelib': '$base/Lib/site-packages',
  33.         'platlib': '$base/Lib/site-packages',
  34.         'headers': '$base/Include/$dist_name',
  35.         'scripts': '$base/Scripts',
  36.         'data': '$base' }
  37. INSTALL_SCHEMES = {
  38.     'unix_prefix': {
  39.         'purelib': '$base/lib/python$py_version_short/site-packages',
  40.         'platlib': '$platbase/lib/python$py_version_short/site-packages',
  41.         'headers': '$base/include/python$py_version_short/$dist_name',
  42.         'scripts': '$base/bin',
  43.         'data': '$base' },
  44.     'unix_local': {
  45.         'purelib': '$base/local/lib/python$py_version_short/dist-packages',
  46.         'platlib': '$platbase/local/lib/python$py_version_short/dist-packages',
  47.         'headers': '$base/local/include/python$py_version_short/$dist_name',
  48.         'scripts': '$base/local/bin',
  49.         'data': '$base/local' },
  50.     'deb_system': {
  51.         'purelib': '$base/lib/python$py_version_short/dist-packages',
  52.         'platlib': '$platbase/lib/python$py_version_short/dist-packages',
  53.         'headers': '$base/include/python$py_version_short/$dist_name',
  54.         'scripts': '$base/bin',
  55.         'data': '$base' },
  56.     'unix_home': {
  57.         'purelib': '$base/lib/python',
  58.         'platlib': '$base/lib/python',
  59.         'headers': '$base/include/python/$dist_name',
  60.         'scripts': '$base/bin',
  61.         'data': '$base' },
  62.     'unix_user': {
  63.         'purelib': '$usersite',
  64.         'platlib': '$usersite',
  65.         'headers': '$userbase/include/python$py_version_short/$dist_name',
  66.         'scripts': '$userbase/bin',
  67.         'data': '$userbase' },
  68.     'nt': WINDOWS_SCHEME,
  69.     'nt_user': {
  70.         'purelib': '$usersite',
  71.         'platlib': '$usersite',
  72.         'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
  73.         'scripts': '$userbase/Scripts',
  74.         'data': '$userbase' },
  75.     'mac': {
  76.         'purelib': '$base/Lib/site-packages',
  77.         'platlib': '$base/Lib/site-packages',
  78.         'headers': '$base/Include/$dist_name',
  79.         'scripts': '$base/Scripts',
  80.         'data': '$base' },
  81.     'mac_user': {
  82.         'purelib': '$usersite',
  83.         'platlib': '$usersite',
  84.         'headers': '$userbase/$py_version_short/include/$dist_name',
  85.         'scripts': '$userbase/bin',
  86.         'data': '$userbase' },
  87.     'os2': {
  88.         'purelib': '$base/Lib/site-packages',
  89.         'platlib': '$base/Lib/site-packages',
  90.         'headers': '$base/Include/$dist_name',
  91.         'scripts': '$base/Scripts',
  92.         'data': '$base' },
  93.     'os2_home': {
  94.         'purelib': '$usersite',
  95.         'platlib': '$usersite',
  96.         'headers': '$userbase/include/python$py_version_short/$dist_name',
  97.         'scripts': '$userbase/bin',
  98.         'data': '$userbase' } }
  99. SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
  100.  
  101. class install(Command):
  102.     description = 'install everything from build directory'
  103.     user_options = [
  104.         ('prefix=', None, 'installation prefix'),
  105.         ('exec-prefix=', None, '(Unix only) prefix for platform-specific files'),
  106.         ('home=', None, '(Unix only) home directory to install under'),
  107.         ('user', None, "install in user site-package '%s'" % USER_SITE),
  108.         ('install-base=', None, 'base installation directory (instead of --prefix or --home)'),
  109.         ('install-platbase=', None, 'base installation directory for platform-specific files ' + '(instead of --exec-prefix or --home)'),
  110.         ('root=', None, 'install everything relative to this alternate root directory'),
  111.         ('install-purelib=', None, 'installation directory for pure Python module distributions'),
  112.         ('install-platlib=', None, 'installation directory for non-pure module distributions'),
  113.         ('install-lib=', None, 'installation directory for all module distributions ' + '(overrides --install-purelib and --install-platlib)'),
  114.         ('install-headers=', None, 'installation directory for C/C++ headers'),
  115.         ('install-scripts=', None, 'installation directory for Python scripts'),
  116.         ('install-data=', None, 'installation directory for data files'),
  117.         ('compile', 'c', 'compile .py to .pyc [default]'),
  118.         ('no-compile', None, "don't compile .py files"),
  119.         ('optimize=', 'O', 'also compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0]'),
  120.         ('force', 'f', 'force installation (overwrite any existing files)'),
  121.         ('skip-build', None, 'skip rebuilding everything (for testing/debugging)'),
  122.         ('record=', None, 'filename in which to record list of installed files'),
  123.         ('install-layout=', None, 'installation layout to choose (known values: deb)')]
  124.     boolean_options = [
  125.         'compile',
  126.         'force',
  127.         'skip-build',
  128.         'user']
  129.     negative_opt = {
  130.         'no-compile': 'compile' }
  131.     
  132.     def initialize_options(self):
  133.         self.prefix = None
  134.         self.exec_prefix = None
  135.         self.home = None
  136.         self.user = 0
  137.         self.prefix_option = None
  138.         self.install_base = None
  139.         self.install_platbase = None
  140.         self.root = None
  141.         self.install_purelib = None
  142.         self.install_platlib = None
  143.         self.install_headers = None
  144.         self.install_lib = None
  145.         self.install_scripts = None
  146.         self.install_data = None
  147.         self.install_userbase = USER_BASE
  148.         self.install_usersite = USER_SITE
  149.         self.install_layout = None
  150.         self.compile = None
  151.         self.optimize = None
  152.         self.extra_path = None
  153.         self.install_path_file = 1
  154.         self.force = 0
  155.         self.skip_build = 0
  156.         self.warn_dir = 1
  157.         self.build_base = None
  158.         self.build_lib = None
  159.         self.record = None
  160.  
  161.     
  162.     def finalize_options(self):
  163.         if self.prefix and self.exec_prefix or self.home:
  164.             if self.install_base or self.install_platbase:
  165.                 raise DistutilsOptionError, 'must supply either prefix/exec-prefix/home or ' + 'install-base/install-platbase -- not both'
  166.         self.install_platbase
  167.         if self.home:
  168.             if self.prefix or self.exec_prefix:
  169.                 raise DistutilsOptionError, 'must supply either home or prefix/exec-prefix -- not both'
  170.         self.exec_prefix
  171.         if self.user:
  172.             if self.prefix and self.exec_prefix and self.home and self.install_base or self.install_platbase:
  173.                 raise DistutilsOptionError("can't combine user with with prefix/exec_prefix/home or install_(plat)base")
  174.         self.install_platbase
  175.         if os.name != 'posix':
  176.             if self.exec_prefix:
  177.                 self.warn('exec-prefix option ignored on this platform')
  178.                 self.exec_prefix = None
  179.             
  180.         
  181.         self.dump_dirs('pre-finalize_{unix,other}')
  182.         if os.name == 'posix':
  183.             self.finalize_unix()
  184.         else:
  185.             self.finalize_other()
  186.         self.dump_dirs('post-finalize_{unix,other}()')
  187.         py_version = string.split(sys.version)[0]
  188.         (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
  189.         self.config_vars = {
  190.             'dist_name': self.distribution.get_name(),
  191.             'dist_version': self.distribution.get_version(),
  192.             'dist_fullname': self.distribution.get_fullname(),
  193.             'py_version': py_version,
  194.             'py_version_short': py_version[0:3],
  195.             'py_version_nodot': py_version[0] + py_version[2],
  196.             'sys_prefix': prefix,
  197.             'prefix': prefix,
  198.             'sys_exec_prefix': exec_prefix,
  199.             'exec_prefix': exec_prefix,
  200.             'userbase': self.install_userbase,
  201.             'usersite': self.install_usersite }
  202.         self.expand_basedirs()
  203.         self.dump_dirs('post-expand_basedirs()')
  204.         self.config_vars['base'] = self.install_base
  205.         self.config_vars['platbase'] = self.install_platbase
  206.         if DEBUG:
  207.             pprint = pprint
  208.             import pprint
  209.             print 'config vars:'
  210.             pprint(self.config_vars)
  211.         
  212.         self.expand_dirs()
  213.         self.dump_dirs('post-expand_dirs()')
  214.         if self.user:
  215.             self.create_home_path()
  216.         
  217.         if self.install_lib is None:
  218.             if self.distribution.ext_modules:
  219.                 self.install_lib = self.install_platlib
  220.             else:
  221.                 self.install_lib = self.install_purelib
  222.         
  223.         self.convert_paths('lib', 'purelib', 'platlib', 'scripts', 'data', 'headers', 'userbase', 'usersite')
  224.         self.handle_extra_path()
  225.         self.install_libbase = self.install_lib
  226.         self.install_lib = os.path.join(self.install_lib, self.extra_dirs)
  227.         if self.root is not None:
  228.             self.change_roots('libbase', 'lib', 'purelib', 'platlib', 'scripts', 'data', 'headers')
  229.         
  230.         self.dump_dirs('after prepending root')
  231.         self.set_undefined_options('build', ('build_base', 'build_base'), ('build_lib', 'build_lib'))
  232.  
  233.     
  234.     def dump_dirs(self, msg):
  235.         if DEBUG:
  236.             longopt_xlate = longopt_xlate
  237.             import distutils.fancy_getopt
  238.             print msg + ':'
  239.             for opt in self.user_options:
  240.                 opt_name = opt[0]
  241.                 if opt_name[-1] == '=':
  242.                     opt_name = opt_name[0:-1]
  243.                 
  244.                 if opt_name in self.negative_opt:
  245.                     opt_name = string.translate(self.negative_opt[opt_name], longopt_xlate)
  246.                     val = not getattr(self, opt_name)
  247.                 else:
  248.                     opt_name = string.translate(opt_name, longopt_xlate)
  249.                     val = getattr(self, opt_name)
  250.                 print '  %s: %s' % (opt_name, val)
  251.             
  252.         
  253.  
  254.     
  255.     def finalize_unix(self):
  256.         if self.install_base is not None or self.install_platbase is not None:
  257.             if (self.install_lib is None and self.install_purelib is None or self.install_platlib is None) and self.install_headers is None and self.install_scripts is None or self.install_data is None:
  258.                 raise DistutilsOptionError, 'install-base or install-platbase supplied, but installation scheme is incomplete'
  259.             self.install_data is None
  260.             return None
  261.         if self.user:
  262.             if self.install_userbase is None:
  263.                 raise DistutilsPlatformError('User base directory is not specified')
  264.             self.install_userbase is None
  265.             self.select_scheme('unix_user')
  266.         elif self.home is not None:
  267.             self.select_scheme('unix_home')
  268.         else:
  269.             self.prefix_option = self.prefix
  270.             if self.prefix is None:
  271.                 if self.exec_prefix is not None:
  272.                     raise DistutilsOptionError, 'must not supply exec-prefix without prefix'
  273.                 self.exec_prefix is not None
  274.                 self.prefix = os.path.normpath(sys.prefix)
  275.                 self.exec_prefix = os.path.normpath(sys.exec_prefix)
  276.             elif self.exec_prefix is None:
  277.                 self.exec_prefix = self.prefix
  278.             
  279.             self.install_base = self.prefix
  280.             self.install_platbase = self.exec_prefix
  281.             if self.install_layout:
  282.                 if self.install_layout.lower() in ('deb',):
  283.                     self.select_scheme('deb_system')
  284.                 else:
  285.                     raise DistutilsOptionError('unknown value for --install-layout')
  286.             self.install_layout.lower() in ('deb',)
  287.             if self.prefix_option or 'real_prefix' in sys.__dict__:
  288.                 self.select_scheme('unix_prefix')
  289.             else:
  290.                 self.select_scheme('unix_local')
  291.  
  292.     
  293.     def finalize_other(self):
  294.         if self.user:
  295.             if self.install_userbase is None:
  296.                 raise DistutilsPlatformError('User base directory is not specified')
  297.             self.install_userbase is None
  298.             self.install_base = self.install_platbase = self.install_userbase
  299.             self.select_scheme(os.name + '_user')
  300.         elif self.home is not None:
  301.             self.install_base = self.install_platbase = self.home
  302.             self.select_scheme('unix_home')
  303.         elif self.prefix is None:
  304.             self.prefix = os.path.normpath(sys.prefix)
  305.         
  306.         self.install_base = self.install_platbase = self.prefix
  307.         
  308.         try:
  309.             self.select_scheme(os.name)
  310.         except KeyError:
  311.             raise DistutilsPlatformError, "I don't know how to install stuff on '%s'" % os.name
  312.  
  313.  
  314.     
  315.     def select_scheme(self, name):
  316.         scheme = INSTALL_SCHEMES[name]
  317.         for key in SCHEME_KEYS:
  318.             attrname = 'install_' + key
  319.             if getattr(self, attrname) is None:
  320.                 setattr(self, attrname, scheme[key])
  321.                 continue
  322.         
  323.  
  324.     
  325.     def _expand_attrs(self, attrs):
  326.         for attr in attrs:
  327.             val = getattr(self, attr)
  328.             if val is not None:
  329.                 if os.name == 'posix' or os.name == 'nt':
  330.                     val = os.path.expanduser(val)
  331.                 
  332.                 val = subst_vars(val, self.config_vars)
  333.                 setattr(self, attr, val)
  334.                 continue
  335.         
  336.  
  337.     
  338.     def expand_basedirs(self):
  339.         self._expand_attrs([
  340.             'install_base',
  341.             'install_platbase',
  342.             'root'])
  343.  
  344.     
  345.     def expand_dirs(self):
  346.         self._expand_attrs([
  347.             'install_purelib',
  348.             'install_platlib',
  349.             'install_lib',
  350.             'install_headers',
  351.             'install_scripts',
  352.             'install_data'])
  353.  
  354.     
  355.     def convert_paths(self, *names):
  356.         for name in names:
  357.             attr = 'install_' + name
  358.             setattr(self, attr, convert_path(getattr(self, attr)))
  359.         
  360.  
  361.     
  362.     def handle_extra_path(self):
  363.         if self.extra_path is None:
  364.             self.extra_path = self.distribution.extra_path
  365.         
  366.         if self.extra_path is not None:
  367.             if type(self.extra_path) is StringType:
  368.                 self.extra_path = string.split(self.extra_path, ',')
  369.             
  370.             if len(self.extra_path) == 1:
  371.                 path_file = extra_dirs = self.extra_path[0]
  372.             elif len(self.extra_path) == 2:
  373.                 (path_file, extra_dirs) = self.extra_path
  374.             else:
  375.                 raise DistutilsOptionError, "'extra_path' option must be a list, tuple, or comma-separated string with 1 or 2 elements"
  376.             extra_dirs = len(self.extra_path) == 1(extra_dirs)
  377.         else:
  378.             path_file = None
  379.             extra_dirs = ''
  380.         self.path_file = path_file
  381.         self.extra_dirs = extra_dirs
  382.  
  383.     
  384.     def change_roots(self, *names):
  385.         for name in names:
  386.             attr = 'install_' + name
  387.             setattr(self, attr, change_root(self.root, getattr(self, attr)))
  388.         
  389.  
  390.     
  391.     def create_home_path(self):
  392.         '''Create directories under ~
  393.         '''
  394.         if not self.user:
  395.             return None
  396.         home = convert_path(os.path.expanduser('~'))
  397.         for name, path in self.config_vars.iteritems():
  398.             if path.startswith(home) and not os.path.isdir(path):
  399.                 self.debug_print("os.makedirs('%s', 0700)" % path)
  400.                 os.makedirs(path, 448)
  401.                 continue
  402.             self.user
  403.         
  404.  
  405.     
  406.     def run(self):
  407.         if not self.skip_build:
  408.             self.run_command('build')
  409.             build_plat = self.distribution.get_command_obj('build').plat_name
  410.             if self.warn_dir and build_plat != get_platform():
  411.                 raise DistutilsPlatformError("Can't install when cross-compiling")
  412.             build_plat != get_platform()
  413.         
  414.         for cmd_name in self.get_sub_commands():
  415.             self.run_command(cmd_name)
  416.         
  417.         if self.path_file:
  418.             self.create_path_file()
  419.         
  420.         if self.record:
  421.             outputs = self.get_outputs()
  422.             if self.root:
  423.                 root_len = len(self.root)
  424.                 for counter in xrange(len(outputs)):
  425.                     outputs[counter] = outputs[counter][root_len:]
  426.                 
  427.             
  428.             self.execute(write_file, (self.record, outputs), "writing list of installed files to '%s'" % self.record)
  429.         
  430.         sys_path = map(os.path.normpath, sys.path)
  431.         sys_path = map(os.path.normcase, sys_path)
  432.         install_lib = os.path.normcase(os.path.normpath(self.install_lib))
  433.         if self.warn_dir:
  434.             if self.path_file:
  435.                 pass
  436.             if not (self.install_path_file) and install_lib not in sys_path:
  437.                 log.debug("modules installed to '%s', which is not in Python's module search path (sys.path) -- you'll have to change the search path yourself", self.install_lib)
  438.             
  439.  
  440.     
  441.     def create_path_file(self):
  442.         filename = os.path.join(self.install_libbase, self.path_file + '.pth')
  443.         if self.install_path_file:
  444.             self.execute(write_file, (filename, [
  445.                 self.extra_dirs]), 'creating %s' % filename)
  446.         else:
  447.             self.warn("path file '%s' not created" % filename)
  448.  
  449.     
  450.     def get_outputs(self):
  451.         outputs = []
  452.         for cmd_name in self.get_sub_commands():
  453.             cmd = self.get_finalized_command(cmd_name)
  454.             for filename in cmd.get_outputs():
  455.                 if filename not in outputs:
  456.                     outputs.append(filename)
  457.                     continue
  458.             
  459.         
  460.         if self.path_file and self.install_path_file:
  461.             outputs.append(os.path.join(self.install_libbase, self.path_file + '.pth'))
  462.         
  463.         return outputs
  464.  
  465.     
  466.     def get_inputs(self):
  467.         inputs = []
  468.         for cmd_name in self.get_sub_commands():
  469.             cmd = self.get_finalized_command(cmd_name)
  470.             inputs.extend(cmd.get_inputs())
  471.         
  472.         return inputs
  473.  
  474.     
  475.     def has_lib(self):
  476.         '''Return true if the current distribution has any Python
  477.         modules to install.'''
  478.         if not self.distribution.has_pure_modules():
  479.             pass
  480.         return self.distribution.has_ext_modules()
  481.  
  482.     
  483.     def has_headers(self):
  484.         return self.distribution.has_headers()
  485.  
  486.     
  487.     def has_scripts(self):
  488.         return self.distribution.has_scripts()
  489.  
  490.     
  491.     def has_data(self):
  492.         return self.distribution.has_data_files()
  493.  
  494.     sub_commands = [
  495.         ('install_lib', has_lib),
  496.         ('install_headers', has_headers),
  497.         ('install_scripts', has_scripts),
  498.         ('install_data', has_data),
  499.         ('install_egg_info', (lambda self: True))]
  500.  
  501.